<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
    <meta name="Keywords" content="Server monitor,python web, flask redis, flask http" />
    <meta name="Description" content="Redis Monitor: a python flask server monitor project, include redis and http server." />
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>主机管理</title>

    <!-- Bootstrap core CSS -->
    <link href="/static/res/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/res/css/style.css" rel="stylesheet">
    <link href="/static/res/lib/fileupload/css/fileinput.css" media="all" rel="stylesheet" type="text/css" />

    <link rel="shortcut icon" href="/static/res/favicon.ico"/>
    <link rel="bookmark" href="/static/res/favicon.ico"/>

    <title>DashBoard</title>
</head>
<body>

<div class="container kv-main">
            <div class="page-header">
            <h2>Bootstrap File Input Example </h2>
            </div>
            <form enctype="multipart/form-data" method="post" action="/upload" id="uploadForm">
                <input id="file-0a" class="file" type="file" name="image_file" multiple data-min-file-count="1">
                <br>
                <button type="submit" class="btn btn-primary">Submit</button>
                <button type="reset" class="btn btn-default">Reset</button>
            </form>
    <div id="kv-error-1" style="margin-top:10px;display:none"></div>
<div id="kv-success-1" class="alert alert-success fade in" style="margin-top:10px;display:none"></div>
</div>

{% include "/include/buttom.html" %}
    <script src="/static/res/lib/fileupload/js/fileinput.js" type="text/javascript"></script>
    <script src="/static/res/lib/fileupload/js/fileinput_locale_zh.js" type="text/javascript"></script>
 <script>
	    $("#file-0a").fileinput({
	        'allowedFileExtensions' : ['jpg', 'png','gif'],
	        uploadUrl: "/upload", // server upload action
            uploadAsync: true,
            showPreview: false,
            showUpload : false,
            maxFileCount: 1,
            elErrorContainer: '#kv-error-1'
	    });

	 $("#uploadForm").submit(function(event) {
        var formData = new FormData(this);
        event.preventDefault();
        $.ajax({
            url : '/upload',
            type : 'POST',
            data : formData,
            contentType : false,
            processData : false,
            success : function(data) {
                if (data.result == 'success') {
                    $("#uploadFileDiv").slideToggle("slow");
                } else {
                   alert(data);
                }
            },
            error : function() {
               alert("data-error");
            }
        });

    });
</script>

</body>
</html>